Use AccountPtr in pushNotificationsReady signal in Account rather than raw pointer
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 22 Mar 2023 13:50:48 +0000 (14:50 +0100)
committerJyrki Gadinger <nilsding@nilsding.org>
Tue, 15 Apr 2025 12:13:34 +0000 (14:13 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderman.cpp
src/gui/folderman.h
src/libsync/account.cpp
src/libsync/account.h

index 892c4fef0f44162e521940a03b0dd62a16063471..5ee0737e2eebd3311b1d7f1ce4ee63696709da81 100644 (file)
@@ -982,7 +982,7 @@ void FolderMan::slotStartScheduledFolderSync()
     }
 }
 
-bool FolderMan::pushNotificationsFilesReady(Account *account)
+bool FolderMan::pushNotificationsFilesReady(const AccountPtr &account)
 {
     const auto pushNotifications = account->pushNotifications();
     const auto pushFilesAvailable = account->capabilities().availablePushNotifications() & PushNotificationType::Files;
@@ -1017,7 +1017,7 @@ void FolderMan::slotEtagPollTimerTimeout()
     // Some folders need not to be checked because they use the push notifications
     std::copy_if(folderMapValues.begin(), folderMapValues.end(), std::back_inserter(foldersToRun), [this](Folder *folder) -> bool {
         const auto account = folder->accountState()->account();
-        return !pushNotificationsFilesReady(account.data());
+        return !pushNotificationsFilesReady(account);
     });
 
     qCInfo(lcFolderMan) << "Number of folders that don't use push notifications:" << foldersToRun.size();
@@ -1059,7 +1059,7 @@ void FolderMan::runEtagJobIfPossible(Folder *folder)
         return;
     }
     // When not using push notifications, make sure polltime is reached
-    if (!pushNotificationsFilesReady(folder->accountState()->account().data())) {
+    if (!pushNotificationsFilesReady(folder->accountState()->account())) {
         if (folder->msecSinceLastSync() < polltime) {
             qCInfo(lcFolderMan) << "Can not run etag job: Polltime not reached";
             return;
@@ -2059,7 +2059,7 @@ void FolderMan::slotSetupPushNotifications(const Folder::Map &folderMap)
         // See if the account already provides the PushNotifications object and if yes connect to it.
         // If we can't connect at this point, the signals will be connected in slotPushNotificationsReady()
         // after the PushNotification object emitted the ready signal
-        slotConnectToPushNotifications(account.data());
+        slotConnectToPushNotifications(account);
         connect(account.data(), &Account::pushNotificationsReady, this, &FolderMan::slotConnectToPushNotifications, Qt::UniqueConnection);
     }
 }
@@ -2079,7 +2079,7 @@ void FolderMan::slotProcessFilesPushNotification(Account *account)
     }
 }
 
-void FolderMan::slotConnectToPushNotifications(Account *account)
+void FolderMan::slotConnectToPushNotifications(const AccountPtr &account)
 {
     const auto pushNotifications = account->pushNotifications();
 
index 9ab08c9ab4bc412f77edf223a8d1ee3975a5e795..4c33005bb81c2864fed2d684ad867940354dc28f 100644 (file)
@@ -337,7 +337,7 @@ private slots:
 
     void slotSetupPushNotifications(const OCC::Folder::Map &);
     void slotProcessFilesPushNotification(OCC::Account *account);
-    void slotConnectToPushNotifications(OCC::Account *account);
+    void slotConnectToPushNotifications(const OCC::AccountPtr &account);
 
     void slotLeaveShare(const QString &localFile, const QByteArray &folderToken = {});
 
@@ -369,7 +369,7 @@ private:
     void runEtagJobsIfPossible(const QList<Folder *> &folderMap);
     void runEtagJobIfPossible(Folder *folder);
 
-    bool pushNotificationsFilesReady(Account *account);
+    bool pushNotificationsFilesReady(const OCC::AccountPtr &account);
 
     [[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;
 
index fc7af4d1eb0f3283e6b673cef8eaaf74506d21f9..cf59af7d507e77d31a8e530fd43644ea2d9864d9 100644 (file)
@@ -332,7 +332,7 @@ void Account::trySetupPushNotifications()
 
             connect(_pushNotifications, &PushNotifications::ready, this, [this]() {
                 _pushNotificationsReconnectTimer.stop();
-                emit pushNotificationsReady(this);
+                emit pushNotificationsReady(sharedFromThis());
             });
 
             const auto disablePushNotifications = [this]() {
index 49d9d20e58aedfd1d292d23b77256164b55e4bf6..ae119758f755889584d70a104d0d1355fb005d01 100644 (file)
@@ -460,7 +460,7 @@ signals:
     /// Used in RemoteWipe
     void appPasswordRetrieved(QString);
 
-    void pushNotificationsReady(OCC::Account *account);
+    void pushNotificationsReady(const OCC::AccountPtr &account);
     void pushNotificationsDisabled(OCC::Account *account);
 
     void userStatusChanged();